package controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import pojo.MyUser;
import service.MyUserService;

@Controller
public class RegisterController {

    @Resource
    private MyUserService myUserService;

    @RequestMapping(value = "/register",method = RequestMethod.POST)
    public String register(MyUser myUser,Model model){
        int m = myUserService.add(myUser);
        if (m>0){
            return "login";
        }else{
            model.addAttribute("msg","register error");
            return "suc";
        }

    }

    @RequestMapping(value = "login",method = RequestMethod.POST)
    public String login(MyUser myUser, Model model){
        System.out.println(myUser);
       if (myUser==null){
           model.addAttribute("msg","please input your name and psd");
           return "suc";
       }
       model.addAttribute("msg",myUserService.login(myUser));
       return "suc";
    }
}
